﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using Aandelendelen.Db;

namespace Aandelendelen.Admin
{
	public partial class AdminMainForm : AdminBaseForm
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!this.IsPostBack)
			{
				int count = this.MailsInQueue();

				if (this.lblMailsInQueue != null)
				{
					this.lblMailsInQueue.Text = count.ToString();
				}
			}
		}

		private int MailsInQueue()
		{

			OleDbConnection connection = new OleDbConnection(DbUtils.GetConnectionString(AandelenDelenDb.AandelenDelenMail));

			connection.Open();

			OleDbCommand selectCommand = new OleDbCommand("SELECT Count(*) FROM Mail WHERE DateSent = ?", connection);

			OleDbParameter par = new OleDbParameter("DateSent", OleDbType.Date);
			par.Value = new DateTime(1980, 1, 1);
			selectCommand.Parameters.Add(par);

			int count = (int)selectCommand.ExecuteScalar();

			connection.Close();

			return count;
		}
	}
}